<template>
<onekit-page>
<onekit-view onekit-class="container">
	<div is="onekit-template-head" :DATA="`${JSON.stringify({title:'templateMessage'})}`"></div>
	<onekit-form onekit-class="page-body" report-submit="true" @Submit="submitForm">
		<onekit-view onekit-class="weui-cells__title">点击提交，发送示例模板消息</onekit-view>
		<onekit-view onekit-class="weui-cells weui-cells_after-title">
			<onekit-view onekit-class="weui-cell weui-cell_input">
				<onekit-view onekit-class="weui-cell__hd">
					<onekit-view onekit-class="weui-label">示例地点</onekit-view>
				</onekit-view>
				<onekit-view onekit-class="weui-cell__bd">
					<onekit-input onekit-class="weui-input" type="text" :disabled="true" :value="formData.address" name="address"></onekit-input>
				</onekit-view>
			</onekit-view>
			<onekit-view onekit-class="weui-cell weui-cell_input">
				<onekit-view onekit-class="weui-cell__hd">
					<onekit-view onekit-class="weui-label">示例时间</onekit-view>
				</onekit-view>
				<onekit-view onekit-class="weui-cell__bd">
					<onekit-input onekit-class="weui-input" type="text" :disabled="true" :value="formData.time" name="time"></onekit-input>
				</onekit-view>
			</onekit-view>
			<onekit-view onekit-class="weui-cell weui-cell_input">
				<onekit-view onekit-class="weui-cell__hd">
					<onekit-view onekit-class="weui-label">示例物品</onekit-view>
				</onekit-view>
				<onekit-view onekit-class="weui-cell__bd">
					<onekit-input onekit-class="weui-input" type="text" :disabled="true" :value="formData.name" name="name"></onekit-input>
				</onekit-view>
			</onekit-view>
			<onekit-view onekit-class="weui-cell weui-cell_input">
				<onekit-view onekit-class="weui-cell__hd">
					<onekit-view onekit-class="weui-label">示例单号</onekit-view>
				</onekit-view>
				<onekit-view onekit-class="weui-cell__bd">
					<onekit-input onekit-class="weui-input" type="text" :disabled="true" :value="formData.serial" name="serial"></onekit-input>
				</onekit-view>
			</onekit-view>
		</onekit-view>
		<onekit-view onekit-class="btn-area">
			<onekit-button type="primary" size="40" formType="submit" :loading="loading">点我提交</onekit-button>
		</onekit-view>
	</onekit-form>
	<div is="onekit-template-foot"></div>
</onekit-view>
</onekit-page></template>
<script>
/* eslint-disable */
import Vue from 'vue';
import onekit_template_0 from '../../../common/head.head.vue';Vue.component('onekit-template-head',onekit_template_0);
import onekit_template_1 from '../../../common/foot.foot.vue';Vue.component('onekit-template-foot',onekit_template_1);
const ONEKIT_JSON= {
  "navigationBarTitleText": "模板消息",
  "usingComponents": {
    
  }
};
const ONEKIT_SJS = {
};
import wx from '../../../../weixin2vue/wx.js';
import Macro from '../../../../weixin2vue/Macro.js';
const {getApp,getCurrentPages} = Macro;
import Page from '../../../../weixin2vue/OnekitPage.js';
import Component from '../../../../weixin2vue/OnekitComponent.js';
const templateMessageUrl = require('../../../config').templateMessageUrl;
const app = getApp();
const formData = {
    "address":'T.I.T 造舰厂',
    "time":'2017.01.09',
    "name":'帝国歼星舰',
    "serial":'123456789'
};
export default Page(ONEKIT_JSON,["true","formData","address","time","name","serial","loading"],ONEKIT_SJS,{
    "onShareAppMessage"(){
      return {
        "title":'模板消息',
        "path":'packageAPI/pages/template-message/template-message'
};
    },
    "onLoad"(){
      this.setData({
        formData
});
    },
    "submitForm"(e){
      const self = this;
      const {formId} = e.detail;
      const formData = e.detail.value;
      console.log('form_id is:',formId);
      self.setData({
        "loading":true
});
      app.getUserOpenId(function(err,openid){
      if(!err)
      {
        wx.request({
            "url":templateMessageUrl,
            "method":'POST',
            "data":{
                "form_id":formId,
                openid,
                formData
},
            "success"(res){
              console.log('submit form success',res);
              wx.showToast({
                "title":'发送成功',
                "icon":'success'
});
              self.setData({
                "loading":false
});
            },
            "fail"({errMsg}){
              console.log('submit form fail, errMsg is:',errMsg);
            }
});
      }
else
      {
        console.log('err:',err);
      };
    });
    }
});

</script>
<style 
 lang="css">
@import '/common/lib/weui.css';
</style>